package com.szzg10.thinking.chapter18;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class ChannelCopy {

	public static void main(String[] args) throws IOException {
		FileInputStream fileInputStream = new FileInputStream(BufferedInputFile.FILE_NAME);
		FileChannel in = fileInputStream.getChannel();
		
		FileOutputStream fileOutputStream = new FileOutputStream(BasicFileOutput.FILE_NAME_OUT);
		FileChannel out = fileOutputStream.getChannel();
		
		ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
		while(in.read(byteBuffer) != -1) {
			byteBuffer.flip();
			out.write(byteBuffer);
			byteBuffer.clear();
		}
		
		fileInputStream.close();
		fileOutputStream.close();
	}
}
